package com.dhcc.DRGsHosp.application.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Named;

import org.dayatang.domain.InstanceFactory;
import org.dayatang.querychannel.QueryChannelService;
import org.springframework.transaction.annotation.Transactional;

import com.dhcc.DRGsHosp.application.WardMonitorApplication;

@Named
@Transactional
public class WardMonitorApplicationImpl implements WardMonitorApplication {
	private QueryChannelService queryChannel;

    private QueryChannelService getQueryChannelService(){
       if(queryChannel==null){
          queryChannel = InstanceFactory.getInstance(QueryChannelService.class,"queryChannel");
       }
     return queryChannel;
    }

	@Override
	public Map<String, Object> getDepInfo(String wardCode) {
		String sql = "select dep.dep_code,dep.dep_name,dg.depgroup_code,dg.depgroup_desc from drgs.t_medicalrecord mr "+ 
				"left join drgs.t_department dep on mr.out_dep_code = dep.dep_code "+
				"left join drgs.t_depgroup dg on dep.pardepgroup_code = dg.depgroup_code "+
				"where mr.out_ward_code = '"+wardCode+"' order by mr.out_date desc ";
		List<Object[]> maxDateList = getQueryChannelService().createSqlQuery(sql).list();
		Map<String,Object> result = new HashMap<String,Object>();
		if (!maxDateList.isEmpty()) {
			result.put("depCode",maxDateList.get(0)[0]);
			result.put("depName",maxDateList.get(0)[1]);
			result.put("depGroupCode",maxDateList.get(0)[2]);
			result.put("depGroupName",maxDateList.get(0)[3]);
		}
		return result;
	}
	
	
}
